import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2024-03-10
 * Time: 22:31
 */
public class IODemo8 {
    public static void main(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("aaa/test.txt")){
            while(true){
                byte[] buffer = new byte[1024];
                int n = inputStream.read(buffer);
                if (n == -1) {
                    break;
                }
                String s = new String(buffer,0,n);//此处构造一个 String 是通过前 n 个字节构造而不是整个数组,实际读取文件内容可能不足 1024
                System.out.println(s);
            }
        }
    }
}
